home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 3 / Cream of the Crop 3.iso / comm / wnos5src.zip / ASY.C < prev    next >
Text File  |  1993-10-09  |  4KB  |  160 lines

  1. /* Generic serial line interface routines
  2.  * Copyright 1992 Phil Karn, KA9Q
  3.  */
  4. #include <stdio.h>
  5. #include <ctype.h>        /* used for 'tolower' */
  6. #include "global.h"
  7. #include "config.h"
  8. #ifdef ASY
  9. #include "iface.h"
  10. #include "pktdrvr.h"
  11. #include "netuser.h"
  12. #include "asy.h"
  13. #include "n8250.h"
  14. #include "ax25.h"
  15. #include "kiss.h"
  16. #include "slip.h"
  17. #include "nrs.h"
  18. #include "proc.h"
  19. #include "commands.h"
  20.  
  21. /* Attach a serial interface to the system
  22.  * argv[0]: hardware type, must be "asy"
  23.  * argv[1]: I/O address, e.g., "0x3f8"
  24.  * argv[2]: vector, e.g., "4"
  25.  * argv[3]: mode, may be:
  26.  *        "slip" (point-to-point SLIP)
  27.  *        "ax25" (AX.25 frame format in SLIP for raw TNC)
  28.  *        "nrs" (NET/ROM format serial protocol)
  29.  * argv[4]: interface label, e.g., "sl0"
  30.  * argv[5]: receiver ring buffer size in bytes
  31.  * argv[6]: maximum transmission unit, bytes
  32.  * argv[7]: interface speed, e.g, "9600"
  33.  * argv[8]: optional flags,
  34.  *        "c" for cts flow control
  35.  *        "r" for rlsd (cd) detection
  36.  *
  37.  */
  38. int
  39. asy_attach(int argc,char **argv,void *p)
  40. {
  41.     struct iface *if_asy;
  42.     int cts = 0, dev, rlsd = 0, trigchar = -1, xdev;
  43.     char *ifn;
  44.  
  45. #ifdef AX25
  46.     if(*Mycall == '\0') {
  47.         tputs(Nomycall);
  48.         return -1;
  49.     }
  50. #endif
  51.  
  52.     if(if_lookup(argv[4]) != NULLIF) {
  53.         tprintf(Ifexist,argv[4]);
  54.         return -1;
  55.     }
  56.  
  57.     /* Find unused asy control block */
  58.     for(dev = 0; dev < ASY_MAX; dev++) {
  59.         if(Asy[dev].iface == NULLIF)
  60.             break;
  61.     }
  62.     if(dev >= ASY_MAX){
  63.         tprintf("Max %d async controller\n",ASY_MAX);
  64.         return -1;
  65.     }
  66.     for(xdev = 0; xdev < SLIP_MAX; xdev++) {
  67.         if(Slip[xdev].iface == NULLIF)
  68.             break;
  69.     }
  70.     if(xdev >= SLIP_MAX) {
  71.         tprintf("Max %d devices\n",SLIP_MAX);
  72.         return -1;
  73.     }
  74.  
  75.     /* Create interface structure and fill in details */
  76.     if_asy = mxallocw(sizeof(struct iface));
  77.     if_asy->addr = Ip_addr;
  78.     if_asy->name = strxdup(argv[4]);
  79.     ifn = if_name(if_asy," rx");
  80.     if_asy->mtu = atoi(argv[6]);
  81.     if_asy->dev = dev;
  82.     if_asy->stop = asy_stop;
  83.  
  84.     if(argc > 8){
  85.         if(strchr(argv[8],'c') != NULLCHAR)
  86.             cts = 1;
  87.         if(strchr(argv[8],'r') != NULLCHAR)
  88.             rlsd = 1;
  89.     }
  90.     switch(*argv[3]) {
  91. #ifdef    SLIP
  92.     case 's':
  93.         setencap(if_asy,"SLIP");
  94.         if_asy->ioctl = asy_ioctl;
  95.         if_asy->raw = slip_raw;
  96.         if_asy->xdev = xdev;
  97.  
  98.         Slip[xdev].iface = if_asy;
  99.         Slip[xdev].send = asy_send;
  100.         Slip[xdev].get = get_asy;
  101.         Slip[xdev].type = CL_SERIAL_LINE;
  102.         trigchar = FR_END;
  103.         if_asy->proc = newproc(ifn,256,asy_rx,xdev,NULL,NULL,0);
  104.         break;
  105. #endif
  106. #ifdef    AX25
  107.     case 'a':
  108.         setencap(if_asy,"AX25");
  109.         if_asy->ioctl = kiss_ioctl;
  110.         if_asy->raw = kiss_raw;
  111.         if_asy->xdev = xdev;
  112.         if_asy->hwaddr = strxdup(Mycall);
  113.         init_maxheard(if_asy);
  114.         init_flags(if_asy);
  115.  
  116.         Slip[xdev].iface = if_asy;
  117.         Slip[xdev].kiss[if_asy->port] = if_asy;        /* G1EMM */
  118.         Slip[xdev].send = asy_send;
  119.         Slip[xdev].get = get_asy;
  120.         Slip[xdev].type = CL_KISS;
  121.         trigchar = FR_END;
  122.         if_asy->proc = newproc(ifn,256,asy_rx,xdev,NULL,NULL,0);
  123.         break;
  124. #endif
  125. #ifdef    NRS
  126.     case 'n':
  127.         setencap(if_asy,"AX25");
  128.         if_asy->ioctl = asy_ioctl;
  129.         if_asy->raw = nrs_raw;
  130.         if_asy->xdev = xdev;
  131.  
  132.         if_asy->hwaddr = strxdup(Mycall);
  133.         init_maxheard(if_asy);
  134.         init_flags(if_asy);
  135.  
  136.         Nrs[xdev].iface = if_asy;
  137.         Nrs[xdev].send = asy_send;
  138.         Nrs[xdev].get = get_asy;
  139.         trigchar = ETX;
  140.         if_asy->proc = newproc(ifn,256,nrs_recv,xdev,NULL,NULL,0);
  141.         break;
  142. #endif
  143.     default:
  144.         tprintf("Mode %s unknown for interface %s\n",argv[3],argv[4]);
  145.         xfree(ifn);
  146.         xfree(if_asy->name);
  147.         xfree(if_asy);
  148.         return -1;
  149.     }
  150.     xfree(ifn);
  151.     if_asy->niface = Niface++;
  152.     if_asy->next = Ifaces;
  153.     Ifaces = if_asy;
  154.  
  155.     asy_init(dev,if_asy,argv[1],argv[2],(unsigned)atoi(argv[5]),trigchar,atol(argv[7]),cts,rlsd);
  156.     return 0;
  157. }
  158.  
  159. #endif /* ASY */
  160.